 <?php

	// Functions and Class
	require_once '../framework/header.inc.php';
	
	// Set default page structure
	$page->constructor("home_category");

	// Top books
	$sql = mysql_query("SELECT book_id, book_section_id, book_author_id, book_volume, book_title, book_counter 
						FROM book WHERE book_access != '0' ORDER BY book_counter DESC LIMIT 5");

	if (mysql_num_rows($sql) > 0) {

		while ($row = mysql_fetch_assoc($sql)) {

			$row['book_section'] = implode(mysql_fetch_assoc(mysql_query("SELECT section_name FROM section WHERE section_id=".$row['book_section_id']."")));
			$row['book_author'] = implode(mysql_fetch_assoc(mysql_query("SELECT author_name FROM author WHERE author_id=".$row['book_author_id']."")));
			$row['book_comments'] = mysql_num_rows(mysql_query("SELECT comment_id FROM comment WHERE comment_category_id = '0' AND comment_book_id='".$row['library_id']."'"));
			$row['book_bookmarks'] = mysql_num_rows(mysql_query("SELECT bookmark_id FROM bookmark WHERE bookmark_book_id='".$row['library_id']."'"));
			$topbooks[] = $row;
		}
	}
	
	// Create option values from DB
	$OPTIONS['sections'] = db_indexing("SELECT section_id,section_name FROM section");
	$OPTIONS['authors'] = db_indexing("SELECT author_id,author_name FROM author");


	// Page render
	$page->render("CATEGORY",$page->category());
	$page->render("SECTIONS",$page->sections());
	$page->render("FOOTMENU",$page->navigation("footmenu"));
	$page->render("TOPBOOKS",$topbooks);
	$page->render("PENDING",pending());
	$page->setOptions($OPTIONS);

	// Display all
	$page->show();
?>